package com.class05.api7;

import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/6 16:16
 */
@Controller
@RequestMapping("api")
@ResponseBody
public class ApiController {
    @Autowired
    private ServletContext servletContext;
    @GetMapping("getUrl")
    public String data(HttpServletRequest request,
                       HttpServletResponse response,
                       HttpSession session){
        List<String> list = new ArrayList<>();
        StringBuffer requestURL = request.getRequestURL();
        list.add(requestURL.toString());
        String host = response.getHeader("Host");
        list.add(host);
        String authType = request.getAuthType();
        list.add(authType);
        String id = session.getId();
        list.add(id);
        return list.toString();
    }

    public void data1(HttpServletRequest request,
                      HttpServletResponse response,
                      HttpSession session){
//        使用原生api获取ServletContext
//        作用：1是最大的配置类2.全局最大共享域 3.核心api
//        方案一：request获取  session获取
        ServletContext servletContext = request.getServletContext();
        ServletContext servletContext1 = session.getServletContext();
//        方案二： ServletContext 会自动装入到ioc容器！
//        程序启动ServletContext- ioc容器
//        直接全局注入可以


    }
}
